<template>
  <yy-paging v-model="dataList" @query="queryList" ref="paging" :auto="automatic" @scroll="scroll" :refresher-enabled="false">
    <template #top>
      <u-navbar
        back-text=""
        :is-back="true"
        title="定位"
        :background="{ backgroundColor: isScroll ? '#FFFFFF' : 'transparent' }"
        :border-bottom="false"
        :custom-style="{ transition: 'background-color 0.3s ease-in-out' }"
      >
      </u-navbar>
    </template>
    <template #empty>
      <yy-empty></yy-empty>
    </template>
    <template #loadingMoreNoMore>
      <yy-nomore></yy-nomore>
    </template>
    <view class="p-4">
      <view class="flex gap-3 items-center">
        <view class="flex flex-none gap-1 items-center" @click="repositioning">
          <!-- :class="city ? 'text-[#606368]' : 'text-[#00A9AB]'" -->
          <view class="text-[#606368]">
            {{ city || '重新定位' }}
          </view>
          <image src="/static/dddr45.png" class="size-[.75rem]" mode="aspectFill" />
        </view>
        <view class="flex-1">
          <u-search placeholder="输入详细地址" :show-action="false" v-model="keyword"></u-search>
        </view>
      </view>
    </view>
  </yy-paging>
</template>

<script>
  export default {
    data() {
      return {
        isScroll: false, // 是否滚动
        dataList: [], // 数据列表
        automatic: false, // 是否自动加载
        city: '', // 当前城市
        keyword: '' // 搜索关键词
      }
    },
    onLoad(options) {
      this.city = options.city
    },

    methods: {
      repositioning() {
        if (!this.city) {
          vk.confirm(
            '为了给您提供更好的服务体验，我们需要获取您的位置信息。请在系统设置中开启定位权限，以便为您推荐附近的钓点、查看实时天气等功能。',
            '开启定位提示',
            '去开启',
            '暂不开启',
            res => {
              if (res.confirm) {
                // #ifdef APP-PLUS
                if (uni.getSystemInfoSync().platform == 'ios') {
                  let UIApplication = plus.ios.import('UIApplication')
                  let application = UIApplication.sharedApplication()
                  let NSURL = plus.ios.import('NSURL')
                  // 打开系统设置APP
                  let setting = NSURL.URLWithString('app-settings:')
                  application.openURL(setting)
                  plus.ios.deleteObject(setting)
                  plus.ios.deleteObject(NSURL)
                  plus.ios.deleteObject(application)
                } else {
                  let Intent = plus.android.importClass('android.content.Intent')
                  let Settings = plus.android.importClass('android.provider.Settings')
                  let mainActivity = plus.android.runtimeMainActivity()
                  let intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)
                  mainActivity.startActivity(intent)
                }
                // #endif
              }
            }
          )
        }
      },
      scroll(e) {
        this.isScroll = e.detail.scrollTop > 0
      },
      async queryList(page, limit) {
        this.$refs.paging.complete([1, 1, 1])
      }
    }
  }
</script>

<style lang="scss" scoped></style>
